<html>
<body>


<form action="calculator.php" method="post">
<input type="text" name="inputStr" />
<input type="submit" value="Calculate" />

<?php
error_reporting(0);
if(isset($_POST['inputStr']))
{
$str=$_POST['inputStr'];

$num='(-?\d+(.\d)?\d*)';
$numin='/'.$num.'/';
$op = '[+\/*-]';
$opin='/'.$op.'/';
$num.$op;
$r = '/^('.$num.$op.')*-?\d+(.\d)?\d*$/'; 
//echo "<br/>".$r."<br/>";

if (preg_match($r, $str))
{
try{
eval("\$str = $str;"); 
}

catch(Exception $e)
{$str="error";
}
echo "<br/>Result:<br/>" ;
echo $str;
	
   
}
else
{
    echo "Invalid Expression";
    
}


}
?>

</body>
</html>


